package cn.edu.ytu.edroid.easychart;

import java.util.List;

import cn.edu.ytu.edroid.easychart.EditActivity.EventDatum;

public class ChartAction {
	private List<EventDatum> dataList;
	private String cht;
	private int set;

	public ChartAction(List<EventDatum> dataList, String cht, int set) {
		this.dataList = dataList;
		this.cht = cht;
		this.set = set;
	}

	public String convertToUrl() {
		float maxValue = dataList.get(0).value;

		String data = "";
		String tag = "";

		String barChm = "";
		String lsChm = "";

		for (int i = 0; i < dataList.size(); i++) {
			maxValue = maxValue >= dataList.get(i).value ? maxValue : dataList
					.get(i).value;

			data += dataList.get(i).value;
			tag += dataList.get(i).tag;

			barChm += "t" + dataList.get(i).tag + ",FF0000,0," + i + ",13";
			lsChm += "s,FF0000,0," + i + ",5|t" + dataList.get(i).tag
					+ ",FF0000,0," + i + ",13";

			if (i != dataList.size() - 1) {
				data += ",";
				tag += "|";

				barChm += "|";
				lsChm += "|";
			}
		}

		// URL with chart type and type size
		String url = "http://chart.apis.google.com/chart" //
				+ "?cht="
				+ cht //
				+ "&chma=15,15,15,15"//
				+ "&chds=0," + Float.toString(maxValue); //

		if (cht.equals("p") || cht.equals("p3")) {// 2D or 3D PieChart

			url += "&chdlp=t" // Legend Position
					+ "&chd=t:" + data // Data
					+ "&chdl=" + tag; // Legend

		} else if (cht.equals("bhs")) {

			url += "&chbh=a" // Bar Width Automatic
					+ "&chxt=x,x" // Axis Bottom
					+ "&chxl=1:|Low|Middle|High(%)" //
					+ "&chd=t:" + data//
					+ "&chm=" + barChm//
					+ "&chg=10,0";//

		} else if (cht.equals("bvs")) {

			url += "&chbh=a" // Bar Width Automatic
					+ "&chxt=y,y" // Axis Style
					+ "&chxl=1:|Low|Middle|High(%)" //
					+ "&chd=t:" + data//
					+ "&chm=" + barChm//
					+ "&chg=0,10";//

		} else if (cht.equals("lc")) {
			// testing
			url += "&chxt=x,x,y,y" // Axis Styles
					+ "&chxl=1:||| (%)" + "|3:|Low|Middle|High (%)"//
					+ "&chls=1" // Line Style
					+ "&chd=t:" + data//
					+ "&chm=" + lsChm//
					+ "&chg=10,10";//

		} else if (cht.equals("ls")) {

			url += "&chls=1" // Line Style
					+ "&chm=" + lsChm //
					+ "&chd=t:" + data//
					+ "&chg=10,10";//

		} else if (cht.equals("r")) {

			url += "&chls=1" // Line Style
					+ "&chxt=x,y" // Axis Styles X,Y
					+ "&chxl=0:|" + tag + "|1:|0|20%|40%|60%|80%|100%"//
					+ "&chd=t:" + data + "," + dataList.get(0).value //
					+ "&chm=B,FF990034,0,0,0";//

		} else if (cht.equals("qr")) {

			url = "http://chart.apis.google.com/chart" //
					+ "?cht="
					+ cht //
					+ "&chma=15,15,15,15"//
					+ "&chl=" + tag;

		} else if (cht.equals("gm")) {

			url += "&chxt=y" // Y-Axis
					+ "&chxl=0:|slow|faster|crazy" //
					+ "&chls=1" // Line Style ????
					+ "&chd=t:" + data //
					+ "&chl=" + tag;//

		}

		return url;
	}
}
